<template>
    <div class="page">
        <div class="score-box">
            <div class="title-cell">我的积分</div>

            <div class="score-num">
                {{ userStore.midNum.score_num }}
                <span class="score-unit">积分</span>
            </div>

            <div class="btn-group">
                <div class="btn-item-1" @click="onTaskList">获取积分</div>
                <div class="btn-item-2" @click="onScoreLottery">积分抽奖</div>
            </div>
        </div>

        <div class="exchange-box">
            <div class="title-cell">积分兑换</div>

            <div class="exchange-list">
                <div class="exchange-item" v-for="(item, index) in exchangeList" :key="item.code">
                    <div class="exchange-item-box" :class="'exchange-item-' + (index + 1)">
                        <div class="exchange-score-num">
                            {{
                                item.score > 10000
                                ? item.score / 10000 + "万"
                                : item.score
                            }}积分
                        </div>
                        <div class="exchange-name">
                            <template v-if="item.type === 'vip'">
                                <p>基础版（Web端）</p>
                                <p>{{ item.value }}天会员</p>
                            </template>
                            <template v-else-if="item.type === 'money'">
                                <p>积分抵扣</p>
                                <p>{{ item.value }}元</p>
                            </template>
                            <template v-else-if="item.type === 'discount'">
                                <p>会员{{ item.value }}折</p>
                                <p>折扣卷</p>
                            </template>
                        </div>
                    </div>
                    <div class="exchange-btn" @click="onExchange(item)">
                        立即兑换
                    </div>
                </div>
            </div>
        </div>

        <div class="bill-box">
            <div class="title-cell">积分账单</div>

            <div class="bill-list">
                <div class="bill-item" v-for="item in userStore.scoreLog" :key="item.id">
                    <div class="bill-item__time">{{ item.createtime }}</div>
                    <div class="bill-item__text">{{ item.desc }}</div>
                    <div class="bill-item__score">
                        {{ item.score >= 0 ? "+" : ""
                        }}{{
    Math.abs(item.score) >= 10000
    ? item.score / 10000 + "万"
    : item.score
}}积分
                    </div>
                </div>
            </div>
        </div>
    </div>

    <DialogTemplateChooseM ref="dialogTemplateChooseRef" @confirm="onConfirm" />
</template>
<script setup>
import { useContent } from ".";

const {
    dialogTemplateChooseRef,
    exchangeList,

    getScoreExchange,
    onTaskList,
    onScoreLottery,
    onExchange,
    onConfirm
} = useContent();

const userStore = useUserStore();
GET_SCORE_LOG();

onMounted(async () => {
    getScoreExchange();
});
</script>
<style lang="scss" scoped>
.page {
    padding: 0 15px 20px;

    .score-box {
        width: 345px;
        height: 175px;
        background: #ffffff;
        border-radius: 3px;
        padding: 16px 15px;

        .score-num {
            display: flex;
            align-items: flex-end;
            justify-content: center;
            font-weight: bold;
            font-size: 40px;
            color: #5085fb;
            margin-top: 30px;
            line-height: 30px;

            .score-unit {
                display: inline-block;
                font-size: 13px;
                height: 13px;
                line-height: 13px;
                color: #111;
            }
        }

        .btn-group {
            display: flex;
            justify-content: center;
            margin-top: 32px;

            .btn-item-1,
            .btn-item-2 {
                display: flex;
                align-items: center;
                justify-content: center;
                width: 100px;
                height: 35px;
                border-radius: 4px;
                font-size: 15px;
                color: #fff;
                cursor: pointer;
            }

            .btn-item-1 {
                background-image: url("https://yzpt-resources.oss-cn-hangzhou.aliyuncs.com/web/images/admin/score/icon-btn-1.jpg");
                margin-right: 30px;
            }

            .btn-item-2 {
                background-image: url("https://yzpt-resources.oss-cn-hangzhou.aliyuncs.com/web/images/admin/score/icon-btn-2.jpg");
            }
        }
    }

    .exchange-box {
        width: 100%;
        background-color: #fff;
        margin-top: 16px;
        padding: 15px 16px 0 16px;

        .exchange-list {
            display: flex;
            flex-wrap: wrap;
            margin-top: 20px;

            .exchange-item {
                margin-right: 13px;
                margin-bottom: 30px;

                &:nth-of-type(2n) {
                    margin-right: 0;
                }
            }

            .exchange-btn {
                width: 80px;
                height: 30px;
                display: flex;
                align-items: center;
                justify-content: center;
                border-radius: 4px;
                border: 1px solid #5085fb;
                color: #5085fb;
                margin: 10px auto 0;
                cursor: pointer;
                font-size: 13px;
            }

            .exchange-item-box {
                position: relative;
                width: 150px;
                height: 100px;
                flex-shrink: 0;
                background-size: 100% 100%;
                border-radius: 4px;
                color: #333;
                font-size: 13px;

                .exchange-score-num {
                    display: flex;
                    align-items: center;
                    justify-content: center;
                    width: 75px;
                    height: 20px;
                    position: absolute;
                    top: 0;
                    left: 0;
                    background-size: 100% 100%;
                    color: #fff;
                    font-size: 14px;
                }

                .exchange-name {
                    padding-top: 40px;
                    text-align: center;
                    line-height: 18px;
                    font-size: 13px;
                    color: #333;
                    font-weight: bold;
                }
            }

            .exchange-item-1 {
                background-image: url("https://yzpt-resources.oss-cn-hangzhou.aliyuncs.com/web/images/admin/score/bg-day1.jpg");

                .exchange-score-num {
                    background-image: url("https://yzpt-resources.oss-cn-hangzhou.aliyuncs.com/web/images/admin/score/icon-lefttop-3.png");
                }
            }

            .exchange-item-2 {
                background-image: url("https://yzpt-resources.oss-cn-hangzhou.aliyuncs.com/web/images/admin/score/bg-day3.jpg");

                .exchange-score-num {
                    background-image: url("https://yzpt-resources.oss-cn-hangzhou.aliyuncs.com/web/images/admin/score/icon-lefttop-3.png");
                }
            }

            .exchange-item-3 {
                background-image: url("https://yzpt-resources.oss-cn-hangzhou.aliyuncs.com/web/images/admin/score/bg-day7.jpg");

                .exchange-score-num {
                    background-image: url("https://yzpt-resources.oss-cn-hangzhou.aliyuncs.com/web/images/admin/score/icon-lefttop-3.png");
                }
            }

            .exchange-item-4 {
                background-image: url("https://yzpt-resources.oss-cn-hangzhou.aliyuncs.com/web/images/admin/score/bg-score.jpg");

                .exchange-score-num {
                    background-image: url("https://yzpt-resources.oss-cn-hangzhou.aliyuncs.com/web/images/admin/score/icon-lefttop-1.png");
                }
            }

            .exchange-item-5 {
                background-image: url("https://yzpt-resources.oss-cn-hangzhou.aliyuncs.com/web/images/admin/score/bg-discount.jpg");

                .exchange-score-num {
                    background-image: url("https://yzpt-resources.oss-cn-hangzhou.aliyuncs.com/web/images/admin/score/icon-lefttop-2.png");
                }
            }
        }
    }

    .bill-box {
        width: 100%;
        height: 180px;
        background-color: #fff;
        margin-top: 16px;
        padding: 15px 16px;

        .bill-list {
            margin-top: 18px;
            overflow: auto;
            height: 120px;

            .bill-item {
                display: flex;
                margin-bottom: 23px;

                &:last-of-type {
                    margin-right: 0;
                }

                &__time {
                    font-size: 13px;
                    color: #333;
                }

                &__text {
                    width: 100px;
                    font-size: 13px;
                    color: #333;
                    margin-left: 10px;
                    text-align: center;
                }

                &__score {
                    color: #5185fb;
                    font-size: 13px;
                    margin-left: auto;
                }
            }
        }
    }

    .title-cell {
        position: relative;
        line-height: 15px;
        padding-left: 9px;
        font-size: 13px;

        &::before {
            position: absolute;
            left: 0;
            top: 0;
            content: "";

            width: 3px;
            height: 15px;
            background: #5085fb;
            border-radius: 2px;
        }
    }
}
</style>
